buildParser = (opts) ->

  parser = require('./compiled_parser').parser

  opts = opts or {}
  parser.args = opts.args or []
  parser.placeholders = opts.placeholders or []
  parser.escFn = opts.escFn or (v) -> v
  
  parser.lexer =
    lex: ->
      [tag, @yytext, @yylineno] = @tokens[@pos++] or ['']
      tag
    
    setInput: (@tokens) ->
        @pos = 0
        
    upcomingInput: -> ""
  
  parser.yy = require('./nodes')
  
  parser.throwUnMatchedParamsExc = ()->
    parser.parseError("number of '?'s in statement string does not match argument count", {})
  
  return parser
  
exports.parser = buildParser()

exports.throwUnMatchedParamsExc = exports.parser.throwUnMatchedParamsExc

exports.parse = (str) -> buildParser().parse(str)  

exports.parse2 = (str, opts) ->    
    buildParser(opts).parse(str)